<!-- 解决layer.open 不居中问题 -->
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>修改记录</title>
    <!--引入抽取css文件-->
    <%@include file="../common/public-css.jsp" %>
    <style>
        .preview {
            height: 250px;
            width: 400px;
            margin-right: 10px;
            margin-bottom: 10px;
            float: left;
            text-align: center
        }

        .preview img {
            width: 100%;
            height: 210px;
            border: 1px solid #eee;
        }
    </style>
</head>
<body ng-app="webApp">
<div style="margin: 15px;">
    <blockquote class="layui-elem-quote"><i class="fa fa-refresh" aria-hidden="true"></i>&nbsp;表单带有 <span
            class="font-red">“*”</span> 号的为必填项.
    </blockquote>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>修改记录</legend>
    </fieldset>
    <form class="layui-form" action="" id="formData" ng-controller="editUserCtr" ng-cloak>


        <div class="layui-form-item">
            <label class="layui-form-label">选择类别<span class="font-red">*</span></label>
            <div class="layui-input-inline">
                <select id="categoryId" lay-filter="categoryFilter" lay-search>
                    <option value="">请选择一类</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="childCategoryId" lay-filter="categoryChildFilter" id="childCategoryId"  lay-search>
                    <option value="">请选择二类</option>
                </select>
            </div>

            <div class="layui-input-inline">
                <select name="itemId" id="itemId"  lay-filter="itemFilter" required lay-verify="required" lay-search>
                    <option value="">请选择体系类别</option>
                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">文件名称<span class="font-red">*</span></label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" autocomplete="off" required lay-verify="required"
                       value="{{item.fileName}}" name="fileName" id="fileName" placeholder="输入名称">
            </div>
        </div>

        <div class="layui-form-item ">
            <label class="layui-form-label"><span>内容</span></label>
            <div class="layui-input-inline">
                <input type="text" name="content" autocomplete="off" id="content"
                       value="{{item.content}}" placeholder="请输入内容" autocomplete="off"
                       class="layui-input" maxlength="250">
            </div>
        </div>

        <div class="layui-form-item ">
            <label class="layui-form-label"><span>备注</span></label>
            <div class="layui-input-inline">
                <input type="text" name="remark" value="{{item.remark}}" id="remark" autocomplete="off"
                       placeholder="请输入备注" autocomplete="off"
                       class="layui-input" maxlength="250">
            </div>
        </div>

        <div class="layui-form-item" id="otherAttachmentDiv">
            <label class="layui-form-label">模版附件<span class="font-red">*</span></label>
            <div class="layui-input-inline">
                <input type="text" disabled autocomplete="off" value="{{item.attachment}}" name="attachment" required
                       lay-verify="required" id="attachment" placeholder="未上传"
                       class="layui-input" maxlength="250">

            </div>
            <div class="layui-input-inline">
                <a href="" download="" id="downModel" class="layui-btn"><i class="layui-icon">&#xe601;</i>下载模版</a>
                <button type="button" class="layui-btn" id="uploadAttachment">
                    <i class="layui-icon">&#xe62f;</i>上传模版
                </button>
            </div>
        </div>

        <input type="hidden" name="id" value="${id}" id="id">

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>


</div>
<!--引入抽取公共js-->
<%@include file="../common/public-js.jsp" %>
<script>

    var webApp = angular.module('webApp', []);
    webApp.controller("editUserCtr", function ($scope, $http, $timeout) {

        $scope.item = null;
        $scope.id = AM.getUrlParam("id");
        AM.ajaxRequestData("get", false, AM.ip + "/record/getRecord", {id: $scope.id}, function (result) {
            $scope.item = result.data;
        });

        var form = null;
        layui.use(['form', 'layedit', 'laydate', 'upload', 'layedit'], function () {
            form = layui.form,
                layer = layui.layer,
                layedit = layui.layedit
                , $ = layui.jquery,
                upload = layui.upload,
                laydate = layui.laydate;

            buildCategorySelect($scope.item.qualityItem.categoryChild.categoryId, "categoryId");
            buildCategoryChildSelect($scope.item.qualityItem.childCategoryId, "childCategoryId", $scope.item.qualityItem.categoryChild.categoryId)
            buildQualityItemSelect($scope.item.itemId,"itemId",$scope.item.qualityItem.childCategoryId);
            $("#downModel").attr("href",Global.imageServer+$scope.item.qualityItem.attachment);
            form.render();

            form.on('select(categoryFilter)', function (data) {
                buildCategoryChildSelect(0, "childCategoryId", data.value)
                form.render();
            });


            form.on('select(categoryChildFilter)', function(data){
                buildQualityItemSelect(0,"itemId",data.value)
                form.render();
            });

            form.on('select(itemFilter)', function(data){
                // 获取附件attachment
                var uri = $(data.elem).find("option:selected").attr("attachment");
                $("#downModel").attr("href",Global.imageServer+uri);
                form.render();
            });

            upload.render({
                elem: '#uploadAttachment' //绑定元素
                , method: 'post'
                , accept: "file"
                , data: {path: 'iems/attachment/record'}
                , url: Global.imageServer + 'upload/files/' //上传接口
                , done: function (res) {
                    //上传完毕回调
                    console.log(res.body[0].sourcePath)
                    $("#attachment").val(res.body[0].sourcePath);
                }
                , error: function () {
                    //请求异常回调
                    layer.msg("上传失败");
                }
            });
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            data.field.id = $("#id").val();
            AM.ajaxRequestData("post", false, AM.ip + "/qualityItem/save", data.field, function (result) {
                if (result.flag == 0 && result.code == 200) {
                    //关闭iframe页面
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                    window.parent.closeNodeIframe();
                }
            });
            return false;
        });
    });

</script>
</body>
</html>
